<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>3-4</title>
    <style type="text/css">
        body{font:12px/1.5;text-align:center;}
        .f-text{width:50px;border:1px solid #ccc;background:#f0f0f0;font-family:inherit;padding:3px;}
        .f-btn{margin:0 10px;}
        strong{padding:0 10px;}
        span{font-weight:700;color:red;}
    </style>
</head>
<body>
<input type="text" class="f-text" />
<strong>vs</strong>
<input type="text" class="f-text" />
<input type="button" class="f-btn" value="最大的数是 >>"/>
<span>？</span>
<script type="text/javascript">
    window.onload = function(){
        var inputs = document.getElementsByTagName("input");
        var span = document.getElementsByTagName("span")[0];

        var size = inputs.length;
        for(var i=0;i<size-1;i++){
            inputs[i].onkeyup = function(){
                this.value = this.value.replace(/[^\d]/,"");
            };
        }

        inputs[2].onclick = function(){
            //if(inputs[0].value == "" || inputs[1].value == "")alert("请输入");
            //span.innerHTML = inputs[0].value > inputs[1].value ? inputs[0].value : inputs[1].value;
            //alert(inputs[0].value+":"+inputs[1].value);
            (inputs[0].value == "" || inputs[1].value == "")?alert("请输入"):
                span.innerHTML = Math.max(inputs[0].value,inputs[1].value);
        };


    };

    //------------------------
    //这个示例..最巧妙三目运算
    //
    //2:(inputs[0].value == "" || inputs[1].value=="")?alert("ff"):
    //span.innerHTML = Math.max(inputs[0].value,inputs[1].value);


</script>
</body>
</html>